<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : listStudentHistory.php
 *  called only via ajax 
 *  List a history timeline of student access to content
 *  @ 
 */  
 

checkSession();

require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3user.php';
require '../../includes/classes/WS3course.php';
require '../../includes/classes/WS3lesson.php';
require '../../includes/classes/WS3module.php';

$user = new WS3_User(); 
$s="";

// must be an admin/headmaster/teacher
if ( isset( $_POST['student_id'] ) && ( $session->userType()<'4') )
{
  $user->setUserID( $_POST['student_id'] );
}else // student 
{
  $user->setUserID( $session->userID() );
}


if (isset( $_POST['id'] ) ) // we only want the history of this course id
{
    $s="AND course_id='".$_POST['id']."'";
}
//
if ($user->ID() )
{

  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing access  for:'.$user->FullName() );
  $table->addColumnTH('Date');
  $table->addColumnTH('Content');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);
  
  
  $db=new WS3_Database();

  
// $$TODO to do selective depening on course, lesson etc
 $q="SELECT uh.id AS uhid , uh.date_access AS uhda, uh.content_id AS uhcid,
 c.name AS cname, m.name AS mname
  FROM 
  `user_history` AS uh
  RIGHT JOIN `content` AS c ON c.id=uh.content_id
  RIGHT JOIN `module` AS m ON m.id=c.module_id
  WHERE uh.user_id = '".$user->ID()."'
  $s
  ORDER BY date_access
  "; 

  
  if ($db->query($q))
  {
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('uhid'), array(
       'Date' => javaSafeString( $db->f('uhda') ),
       'Content' => javaSafeString( $db->f('mname').":".$db->f('cname') )
        
        ));
  
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
     echo $table->display();
    $message="Listing";
   
  }else{
    $message="Error : Empty list";
  }


}
/** Get menu */
if ( $session->userType()<'3' ){
require '../../includes/menus/topCoursesStudent.php';
}else{
require '../../includes/menus/topGoContent.php';
}

$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";
if (W3DEBUG)  $debug=new WS3_Debug();

?>

